/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.object;

import java.awt.Cursor;
import net.worlds.WorldsException;
import net.worlds.Main;
import net.worlds.ui.UI;
import org.jbox2d.common.Vec2D;


public class GrabTool extends Tool{
    public GrabTool() throws WorldsException
    {
        super("GrabTool");
    }
    @Override
    public void selected()
    {
        if(!Main.noView)
        {
            UI.mouseMode = UI.MODE_GRAB;
            UI.setMouseImage(null);
            UI.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
    }
    @Override
    public void mouseDown(int b, Vec2D pos)
    {
        super.mouseDown(b, pos);
        if(b == 3 && UI.getSelected().size() == 1 && UI.getSelected().get(0) instanceof Part)
        {
            try {
                Part p = (Part) UI.getSelected().get(0);
                if (p.getBooleanProp("Fixed") == true) {
                    p.setProp("Fixed", false, true);
                } else {
                    p.setProp("Fixed", true, true);
                }
            } catch (WorldsException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    @Override
    public void deselected()
    {
        try {
            if(!Main.noView)
                UI.clearSelection(false);
        } catch (WorldsException ex) {
            ex.printStackTrace();
        }
        UI.clearMouseMode();
    }
}

/*
link(script.Parent.Selected, function() print("S") end)
link(script.Parent.Deselected, function() print("d") end)
link(script.Parent.MouseDown, function(b, p) print(b); print(p); end)
link(script.Parent.MouseUp, function(p) print(p) end)
 */